package com.gakj.truck.third.api.service;

import com.gakj.truck.third.api.mapper.TruckImgDtoMapper;
import com.gakj.truck.third.core.domain.TruckImgDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by gc on 2016/5/10.
 */
@Service
public class TruckImgDtoService {


    @Autowired
    TruckImgDtoMapper truckImgDtoMapper;


    public List<TruckImgDto> getListByTruckId(Long truckId){
        return truckImgDtoMapper.getAllList(truckId);
    }

    public List<Map<String,String>> getEchoList(Long truckId){
        List<Map<String,String>> list = new ArrayList<>();
        List<TruckImgDto> listByTruckId = getListByTruckId(truckId);

        for(TruckImgDto truckImgDto : listByTruckId){
            Map<String,String> map = new HashMap<>();
            map.put("url","#"+truckImgDto.getLocation()+truckImgDto.getImgpath());
            map.put("position",truckImgDto.getLocation());
            list.add(map);
        }
        return list;
    }

    public void deleteByTruckid(Long truckid){
        truckImgDtoMapper.deleteByTruckid(truckid);
    }

    public void deleteByid(Long id){
        truckImgDtoMapper.deleteByid(id);
    }

    public Long save(TruckImgDto dto){
        return truckImgDtoMapper.save(dto);
    }

    public void batchSave(List<TruckImgDto> imgDtos) {
        truckImgDtoMapper.batchSave(imgDtos);
    }
}
